import App from "./App.vue";
import router from "./router";
import ElementPlus from "element-plus";
import mitt from "mitt";
import pinia from "./stores/index";
import "element-plus/dist/index.css";
import "element-plus/theme-chalk/display.css";
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
import "./styles/index.less";
import { createApp } from "vue";
import { loadLang } from "./lang/index";

// modules import mark, Please do not remove.
function setRem() {
  const baseSize = 100;
  const scale = document.documentElement.clientWidth / 1920;
  document.documentElement.style.fontSize = baseSize * scale + "px";
}

async function start() {
  const app = createApp(App);

  app.use(router);

  app.use(pinia);

  // 全局语言包加载
  const i18n = await loadLang(app);
  app.use(ElementPlus, { i18n: i18n.global.t });

  // 全局注册
  for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
  }
  // 初始化
  setRem();
  // 改变窗口大小时重新设置 rem
  window.addEventListener("resize", () => {
    setRem();
  });
  app.mount("#app");

  // modules start mark, Please do not remove.

  app.config.globalProperties.eventBus = mitt();
}

start();
